home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 23 / AMIGAplus Sonderheft 23 (2000)(Falke)(DE)[!].iso / Tools / Text-Viewer / MSWordView / mswordview_src / field.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-11-06  |  4.2 KB  |  174 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5. #include <time.h>
  6. #include "config.h"
  7. #include "mswordview.h"
  8.  
  9. extern FILE *erroroutput;
  10. extern FILE *outputfile;
  11. extern sep *currentsep;
  12. extern int inaheaderfooter;
  13. extern int sectionpagenumber;
  14. extern int sectionno;
  15.  
  16.  
  17. void decode_field(FILE *main,field_info *magic_fields,long *cp,U8 *fieldwas,long *swallowcp1,long *swallowcp2)
  18.     {
  19.     time_t timep;
  20.     struct tm *times;
  21.     char date[1024];
  22.     /*
  23.     called at the start of a field, find the field associated
  24.     with that cp and decode meaning, process to end of field
  25.     */
  26.  
  27.     /*wont deal with enbedded fields yet\n*/
  28.     int i=0;
  29.     int type=0;
  30.  
  31.     *swallowcp1 = -1;
  32.     *swallowcp2 = -1;
  33.  
  34.     error(erroroutput,"decoding field with cp %x\n",*cp);
  35.  
  36.     if (magic_fields != NULL)
  37.         {
  38.         while(i<magic_fields->no+1)
  39.             {
  40.             error(erroroutput,"field entry says %d (%x)\n",i,magic_fields->cps[i]);
  41.             if (magic_fields->cps[i] == *cp)
  42.                 {
  43.                 error(erroroutput,"found field entry at %d\n",i);
  44.                 type = (magic_fields->flds[i*2])&0x1f;
  45.                 error(erroroutput,"type is %d \n",type);
  46.                 break;
  47.                 }
  48.             i++;
  49.             }
  50.  
  51.         switch(type)
  52.             {
  53.             case 19:
  54.                 /*beggining a field*/
  55.                 *fieldwas = magic_fields->flds[(i*2)+1];
  56.                 switch (*fieldwas)
  57.                     {
  58.                     case 10:    /*style reference*/
  59.                     case 12: /*sequence mark, make a hyperlink later on*/
  60.                     case 68:
  61.                         break;
  62.                     case 88:
  63.                         error(erroroutput,"HYPERLINK\n");
  64.                         /*
  65.                         fprintf(outputfile,"<a href=\"");
  66.                         */
  67.                         fprintf(outputfile,"<a href=");
  68.                         *swallowcp1 = magic_fields->cps[i];    /*beginning of field*/
  69.                         *swallowcp2 = magic_fields->cps[i+1]-1; /*end of the first part*/
  70.                         break;
  71.                     case 33:
  72.                         if ((currentsep != NULL) && (inaheaderfooter))
  73.                             {
  74.                             error(erroroutput,"soing nfc\n");
  75.                             error(erroroutput,"nfcPgn is %d\n",currentsep->nfcPgn);
  76.                             decode_list_nfc(§ionpagenumber,currentsep->nfcPgn);
  77.                             sectionpagenumber--;
  78.                             }
  79.                         else 
  80.                             fprintf(outputfile,"%d",sectionpagenumber);
  81.                         error(erroroutput,"sectionpagenumber is now %d, inaheaderfooter is %d\n",sectionpagenumber,inaheaderfooter);
  82.                         break;
  83.                     case 65:
  84.                         fprintf(outputfile,"%d",sectionno);
  85.                         error(erroroutput,"sectionno is now %d\n",sectionno);
  86.                         break;
  87.                     case 26:
  88.                         fprintf(outputfile,"unknown # of pages");
  89.                         break;
  90.                     case 31:
  91.                         timep = time(NULL);
  92.                         times = localtime(&timep);
  93.                         strftime(date,1024,"%x",times);
  94.                         error(erroroutput,"output date as %s\n",date);
  95.                         fprintf(outputfile,"%s",date);
  96.                         break;
  97.                     case 32:
  98.                         timep = time(NULL);
  99.                         times = localtime(&timep);
  100.                         strftime(date,1024,"%X",times);
  101.                         error(erroroutput,"output time as %s\n",date);
  102.                         fprintf(outputfile,"%s",date);
  103.                         break;
  104.                     case 29:
  105.                         error(erroroutput,"spitting out original filename\n");
  106.                         break;
  107.                     case 13:
  108.                         error(erroroutput,"spitting out toc\n");
  109.                         break;
  110.                     case 37:
  111.                         *swallowcp1 = magic_fields->cps[i];    /*beginning of field*/
  112.                         *swallowcp2 = magic_fields->cps[i+1]-1; /*end of the first part*/
  113.                     default:
  114.                         error(erroroutput,"unsupported field %d\n",*fieldwas);
  115.                         break;
  116.                     }
  117.                 break;
  118.             case 20:
  119.                 switch (*fieldwas)
  120.                     {
  121.                     case 68:
  122.                     case 65:
  123.                     case 33:
  124.                     case 26:
  125.                     case 10:
  126.                     case 12:
  127.                         break;
  128.                     case 88:
  129.                         error(erroroutput,"HYPERLINK middle\n");
  130.                         /*
  131.                         fprintf(outputfile,"\">");
  132.                         */
  133.                         fprintf(outputfile,">");
  134.                         break;
  135.                     case 29:
  136.                         error(erroroutput,"filename middle\n");
  137.                         break;
  138.                     case 13:
  139.                         error(erroroutput,"toc middle\n");
  140.                         break;
  141.                     default:
  142.                         error(erroroutput,"unsupported field %d\n",*fieldwas);
  143.                         break;
  144.                     }
  145.                 error(erroroutput,"field middle reached\n");
  146.                 break;
  147.             case 21:
  148.                 switch (*fieldwas)
  149.                     {
  150.                     case 10:
  151.                     case 12:
  152.                     case 68:
  153.                     case 65:
  154.                     case 33:
  155.                     case 26:
  156.                     case 37:
  157.                         break;
  158.                     case 88:
  159.                         error(erroroutput,"HYPERLINK end\n");
  160.                         fprintf(outputfile,"</a>");
  161.                         break;
  162.                     default:
  163.                         error(erroroutput,"unsupported field %d\n",*fieldwas);
  164.                         break;
  165.                     }
  166.                 error(erroroutput,"field end reached\n");
  167.                 break;
  168.             default:
  169.                 error(erroroutput,"field wierdness!!\n");
  170.                 break;
  171.             }
  172.         }
  173.     }
  174.